//--------------------------------------- NOTES ------------------------------------------------------//
* This table is Table 5 in the paper
//--------------------------------------------------------------------------------------------------------//

cd  "/YOUR_LOCAL_DIRECTORY" //setting the working directory
clear all //remove all data, labels, matrices etc (incl. Mata functions)
use August17ChanRoth.dta, clear

** drop player who participated mulitple times
drop if room=="HRSUs" | room=="FQkZh"

* Create the key treatment variable
gen byte status_quo = treatment=="status_quo"
la var status_quo  "Status Quo"

* Create 2 row for each observation
expand 2, gen(dupindicator)

* Generate blue ball count variable 
gen urn_blue = player2highbluecount if dupindicator==1 // blue count for high blue urn 
replace urn_blue = player2lowbluecount if dupindicator==0 // blue count for high blue urn 

* High blue urn indicator
gen byte highballurn = dupindicator==1
la var highballurn  "High Blue Urn"
* Indicator of whether urn was transplanted:
gen byte transplanted_thisurn = player2action=="MixWithBothBlue"
replace transplanted_thisurn=1 if player2action=="MixWithLowBlue" & dupindicator==0
replace transplanted_thisurn=1 if player2action=="MixWithHighBlue" & dupindicator==1

* Expected blue given actual TX decisions

gen expected_mortality = 1-urn_blue/100 if transplanted_thisurn==0
replace expected_mortality = 1-(urn_blue+player1bluecount)/200 if transplanted_thisurn==1

* indicator for very high risk or very low risk patients
gen byte extremepatient = player2highbluecount>=90 | player2lowbluecount<=10

* Make table

eststo clear

eststo: quietly reg expected_mortality  status_quo,  vce(cluster room) // Compare expected mortality rate by treatment group
eststo: quietly reg expected_mortality  status_quo if dupindicator==0,  vce(cluster room) // Compare expected mortality rate by treatment group
eststo: quietly reg expected_mortality  status_quo if dupindicator==1,  vce(cluster room) // Compare expected mortality rate by treatment group

eststo: quietly reg expected_mortality  status_quo if extremepatient==1,  vce(cluster room) // Compare expected mortality rate by treatment group
eststo: quietly reg expected_mortality  status_quo if dupindicator==0 & extremepatient==1,  vce(cluster room) // Compare expected mortality rate by treatment group
eststo: quietly reg expected_mortality  status_quo if dupindicator==1 & extremepatient==1,  vce(cluster room) // Compare expected mortality rate by treatment group

eststo: quietly reg expected_mortality  status_quo if extremepatient==0,  vce(cluster room) // Compare expected mortality rate by treatment group
eststo: quietly reg expected_mortality  status_quo if dupindicator==0 & extremepatient==0,  vce(cluster room) // Compare expected mortality rate by treatment group
eststo: quietly reg expected_mortality  status_quo if dupindicator==1 & extremepatient==0,  vce(cluster room) // Compare expected mortality rate by treatment group

local titles "& All & Low Blue & High Blue & All & Low Blue & High Blue & All & Low Blue & High Blue \\"
local numbers "& (1) & (2) & (3) & (4) & (5) & (6) & (7) & (8) & (9) \\ \hline"


esttab using table_expectedmortality.tex, se r2  keep(status_quo _cons) star(+ 0.1 * 0.05 ** 0.01) b(3) mgroups("All Urns" "At Least One Urn Sickest or Healthiest" "No Urn Sickest or Healthiest", pattern(1 0 1 0 1) prefix(\multicolumn{3}{c}{) suffix(}) span) mlabels(none) nonumbers posthead("`numbers'") label title("Impact on Expected Bad Outcomes (Red Balls Drawn) Based on Actual Mixing Behavior") substitute([htbp] [!htbp] \begin{tabular} \small\begin{tabular} {l} {p{\linewidth}}) addnotes("(Robust, clustered by player-pairings)") stat(N r2, label("N" "\[R^2\]") fmt(a3 %9.3fc))
